bitkeeper revision 1.724 (402ca374dzl4iEPzK71tvTWpDEYxgw)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Fri, 13 Feb 2004 10:14:12 +0000 (10:14 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Fri, 13 Feb 2004 10:14:12 +0000 (10:14 +0000)
XenoUtil.py, xc_dom_control.py, VBD-HOWTO.txt:
  Merge toolset changes from v1.2.

docs/VBD-HOWTO.txt
tools/examples/xc_dom_control.py
tools/xc/py/XenoUtil.py

index b1d12a5f963f77952c575bdb5d7bcf286d2b3066..870ea2e040604b39c2b8891c58f796ca89f61962 100644 (file)
@@ -204,6 +204,26 @@ just before deallocation (automated support for this may be added at a later
 date).
 
 
+Side note: The xvd* devices
+---------------------------
+
+The examples in this document make frequent use of the xvd* device nodes for
+representing virtual block devices.  It is not a requirement to use these with
+Xen, since VBDs can be mapped to any IDE or SCSI device node in the system.
+Changing the the references to xvd* nodes in the examples below to refer to
+some unused hd* or sd* node would also be valid.
+
+They can be useful when accessing VBDs from dom0, since binding VBDs to xvd*
+devices under will avoid clashes with real IDE or SCSI drives.
+
+There is a shell script provided in tools/misc/xen-mkdevnodes to create these
+nodes.  Specify on the command line the directory that the nodes should be
+placed under (e.g. /dev):
+
+> cd {root of Xen source tree}/tools/misc/
+> ./xen-mkdevnodes /dev
+
+
 Dynamically Registering VBDs
 ----------------------------
 
@@ -306,7 +326,7 @@ vbd_list variable, for instance using the line:
 (Note that you need to use quotes here, since config files are really small
 Python scripts.)
 
-To specify the mapping on the commandline, you'd use the -d switch and supply
+To specify the mapping on the command line, you'd use the -d switch and supply
 the triple as the argument, e.g.:
 
 > xc_dom_create.py [other arguments] -d phy:hdc,/dev/whatever,r
index 59d137837e91ba9561a03f738633f080bb81c599..638a509106f7792a46497d4a6c845eb02a56c337 100755 (executable)
@@ -229,6 +229,10 @@ elif cmd == 'vbd_add':
 
     segments = XenoUtil.lookup_disk_uname(uname)
 
+    if not segments:
+        print "Lookup Failed"
+        sys.exit(1)
+
     if XenoUtil.vd_extents_validate(segments,writeable) < 0:
        print "That mapping is too unsafe for the current VBD expertise level"
        sys.exit(1)
index 68f4f02f54f85008e9dd018dd4c935507c213a8a..e3b49bd99a586f3400ed227acd79cea180aef02d 100644 (file)
@@ -314,7 +314,7 @@ def vd_create(size_mb, expiry):
                   FROM vdisks NATURAL JOIN vdisk_extents
                                                   NATURAL JOIN vdisk_part
                   WHERE expires AND expiry_time <= datetime('now')
-                  ORDER BY expiry_time asc, vdisk_extent_no desc
+                  ORDER BY expiry_time ASC, vdisk_extent_no DESC
                """)  # aims to reuse the last extents
                      # from the longest-expired disks first
 
@@ -389,7 +389,7 @@ def vd_lookup(id):
 
     if not count:
         cx.close()
-        return -1
+        return None
 
     cu.execute("SELECT size from vdisks WHERE vdisk_id = " + id)
     real_size, = cu.fetchone()
@@ -410,6 +410,7 @@ def vd_lookup(id):
                                              NATURAL JOIN vdisk_part
                                                 
                   WHERE vdisk_extents.vdisk_id = """ + id
+               + " ORDER BY vdisk_extents.vdisk_extent_no ASC"
                )
 
     extent_tuples = cu.fetchall()
@@ -509,7 +510,7 @@ def vd_enlarge(vdisk_id, extra_size_mb):
                   FROM vdisks NATURAL JOIN vdisk_extents
                                                   NATURAL JOIN vdisk_part
                   WHERE expires AND expiry_time <= datetime('now')
-                  ORDER BY expiry_time asc, vdisk_extent_no desc
+                  ORDER BY expiry_time ASC, vdisk_extent_no DESC
                """)  # aims to reuse the last extents
                      # from the longest-expired disks first
 
@@ -779,7 +780,7 @@ def vd_cp_to_file(vdisk_id,filename):
 
     extents = vd_lookup(vdisk_id)
 
-    if extents < 0:
+    if not extents:
         return -1
     
     file_idx = 0 # index into source file, in sectors
@@ -827,9 +828,12 @@ def vd_read_from_file(filename,expiry):
     returns [string] : vdisk ID for the destination vdisk
     """
 
-    size_sectors = os.stat(filename).st_size / 512
+    size_bytes = os.stat(filename).st_size
 
-    vdisk_id = vd_create(size_sectors / ( 2 * 1024 ),expiry)
+    (size_mb,leftover) =  divmod(size_bytes,1048580) # size in megabytes
+    if leftover > 0: size_mb += 1 # round up if not an exact number of MB
+
+    vdisk_id = vd_create(size_mb, expiry)
 
     if vdisk_id < 0:
         return -1
@@ -840,10 +844,12 @@ def vd_read_from_file(filename,expiry):
     cu.execute("""SELECT partition, extent_size, part_extent_no
                   FROM vdisk_part NATURAL JOIN vdisk_extents
                   WHERE vdisk_id =  """ + vdisk_id + """
-                  ORDER BY vdisk_extent_no""")
+                  ORDER BY vdisk_extent_no ASC""")
 
     extents = cu.fetchall()
 
+    size_sectors = size_mb * 2048 # for feeding to dd
+
     file_idx = 0 # index into source file, in sectors
 
     def write_extent_to_vd((partition, extent_size, part_extent_no),
@@ -856,7 +862,7 @@ def vd_read_from_file(filename,expiry):
                   + " count=" + str(min(extent_size, size_sectors - file_idx))
                   + " > /dev/null")
 
-        return file_idx + extent_size
+        return extent_size
 
     for i in extents:
         file_idx += write_extent_to_vd(i, file_idx, filename)